<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/9
 * Time: 20:45
 */
class DbHelper
{
    private $where = array();
    private $data = array();
    private $link = null;
    private $connect_type = '';
    public function __construct()
    {

    }

    public function connect()
    {
      exit('请开启mysql或mysqli或pdo_mysql扩展');
    }
    protected function connectPdo($host, $user, $pass, $port, $db_name)
    {
        $connect_type = 'pdo';
        if (extension_loaded('pdo_mysql')) {
            $connection = new PDO("mysql:host={$host};port:{$port};dbname={$db_name}", $user, $pass);
            return $connection;
        }
        return false;
    }
    protected function connectMysqli($host, $user, $pass, $port, $db_name)
    {
        $connect_type = 'mysqli';
        if (extension_loaded('mysqli')) {
            $connection = new mysqli($host, $user, $pass, $db_name, $port);
            return $connection;
        }
        return false;
    }
    protected function connectMysql($host, $user, $pass, $port, $db_name)
    {
        $connect_type = 'mysql';
        if (extension_loaded('mysql')) {
            $connection = mysql_connect($host . ':' . $port, $user, $pass);
            mysql_select_db($db_name);
            return $connection;
        }
        return false;
    }
}